import java.util.List;

public class ProductList extends AbstractObjectList{
    public ProductList(List<Object> products) {
        super(products);
    }

    @Override
    public AbstractIterator createIterator() {
        return new ProductIterator(this);
    }

    private class ProductIterator implements AbstractIterator{

        private ProductList productList;

        private List<Object> products;

        private int currentIndex=-1;
        public ProductIterator(ProductList list){
            productList = list;
        }
        @Override
        public void next() {
            if (currentIndex < objects.size() - 1) {
                currentIndex++;
            }
        }

        @Override
        public boolean isLast() {
            return currentIndex == objects.size() - 1;
        }

        @Override
        public void previous() {
            if (currentIndex > 0) {
                currentIndex--;
            }
        }

        @Override
        public boolean isFirst() {
            return currentIndex == 0;
        }

        @Override
        public Object getNextItem() {
            if (!isLast()) {
                return objects.get(currentIndex + 1);
            }
            return null;
        }

        @Override
        public Object getPreviousItem() {
            if (!isFirst()) {
                return objects.get(currentIndex - 1);
            }
            return null;
        }

        public void setNewIteratorReverse(){
            currentIndex = objects.size();
        }

    }

}
